<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <ul>
            <template v-for="(book,index) in sorted">
                <li>{{index}}：{{book.name}}  {{book.author}}</li>
               
                <!-- <li>书名：{{book.name}}</li>
                <li>作者：{{book.author}}</li> -->
            </template>
        </ul>
    </div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
    var app = new Vue({
        el:"#app",
        data:{
            // books:{
            //     name : 'adsdf',
            //     author : 'ghghjghjghj',
            //     price:155555
            // }
            books:[
                {
                    name: '《Vue.js实战》',
                    author: '梁*'
                },
                {
                    name: '《JavaScript 语言精粹》',
                    author: 'xiaojun'
                },
                {
                    name: '《JavaScript 高级程序设计》',
                    author: 'xiaoxuan'
                },
            ]
        },
        computed:{
            filter:function(){
                return this.books.filter(function(book){
                    return book.name.match(/JavaScript/);
                })
            },
            sorted:function(){
                return this.books.sort(function (a,b){
                    return a.name.length < b.name.length;
                })
            }
        }

    })
</script>
</html>